__author__ = 'st316'
'''
Implement int sqrt(int x).

Compute and return the square root of x.
sqrt of n is less than n/2+1
'''


class Solution:
    # @param x, an integer
    # @return an integer
    def sqrt(self, x):
        if x <= 0:
            return 0
        high = x / 2 + 1
        low = 0
        while low <= high:
            mid = (high + low) / 2
            t = mid * mid
            if t == x:
                return mid
            elif t < x:
                low = mid + 1
            else:
                high = mid - 1
        return (low + high) / 2


if __name__ == '__main__':
    s = Solution()
    print s.sqrt(2)